From 86a7522040af1fb0c1bb495a9c84f0c6cd7f0b39 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 12 Nov 2009 13:15:40 +0000 Subject: [PATCH] Don't assume vcpu_id's are contiguous in alloc_vcpu When cpu hot-added, this assumption is broken because the hot-added CPU may be brougt online by dom0 in arbitrary order. This patch avoids making this assumption while still linking vcpus in ascending order of identifier. Signed-off-by: Jiang, Yunhong Signed-off-by: Keir Fraser --- xen/common/domain.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index d47b55a939..6d445d61b6 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -176,7 +176,14 @@ struct vcpu *alloc_vcpu( d->vcpu[vcpu_id] = v; if ( vcpu_id != 0 ) - d->vcpu[v->vcpu_id-1]->next_in_list = v; + { + int prev_id = v->vcpu_id - 1; + while ( (prev_id >= 0) && (d->vcpu[prev_id] == NULL) ) + prev_id--; + BUG_ON(prev_id < 0); + v->next_in_list = d->vcpu[prev_id]->next_in_list; + d->vcpu[prev_id]->next_in_list = v; + } /* Must be called after making new vcpu visible to for_each_vcpu(). */ vcpu_check_shutdown(v); -- 2.30.2